Ext.define('ExtJs.view.system.module.UserGrid',{
	extend:'Ext.grid.Panel',
	alias : 'widget.userGrid',
	moduleId:0,
	initComponent:function(){
		var ids=this.moduleId;
		var messageGridStore = Ext.create('ExtJs.store.system.module.UserGridStore',{storeId:'govInfoModuleStore_'+this.moduleId});

		var govInfoModuleGrid = this;
		Ext.apply(this, {
			store:messageGridStore,
			tbar:[
				{text:this.moduleId,id:'add'+govInfoModuleGrid.moduleId},
					{text:'删除',
					iconCls:'delete',
					handler:function(){
						
						
					var storeform = govInfoModuleGrid.getSelectionModel().getSelection()[0];
					Ext.MessageBox.confirm("确认","是否删除用户："+storeform.get("name"),
										function(btn){    
				        //Ext.MessageBox.alert("你单击的按钮是："+btn);  
				        if(btn=="yes")
				        			{
				        			var vid=storeform.get("___key_id");
									Ext.Ajax.request({
										    url: '../servlet/user.delete',
										    params: {
										        id: vid
										    },
										    success: function(response){
										        var text = response.responseText;//取得text
										        var json = Ext.decode(text);//转json
										       // Ext.Msg.alert('信息', json.msg);
										        //alert(text);
										         messageGridStore.load();
										        // process server response here
										    }
										});
				        			}
					}); 
					
					}
					},
					{text:'编辑',
					iconCls:'application_form',
					handler:function(){
					var storeform = govInfoModuleGrid.getSelectionModel().getSelection()[0];
					var w=Ext.create('Ext.window.Window',{title: '修改用户',
						 width: 400,
						minWidth: 200,
						layout: 'anchor',
						closable: true,
						//resizable:false,
						plain: true,
						items: [			        
						        Ext.create('Ext.form.Panel', {
								   // title: '添加用户', 
								    bodyPadding: 5,
								    width: 350,
								    border: false,
								    url: '../servlet/user.update',
								    items: [
									{
									    xtype: 'hiddenfield',
									    name: 'id',
									    value: storeform.get("___key_id")
									   
									}
									,
								            
								    {
								        xtype: 'textfield',
								        name: 'name',
								        fieldLabel: '姓名',
								         value: storeform.get("name"),
								        allowBlank: false  // requires a non-empty value
								    },
								    {
								        xtype: 'textfield',
								        name: 'account',
								         value: storeform.get("account"),
								        fieldLabel: '账号'
								    }
								    ,
								    {
								        xtype: 'textfield',
								        name: 'password',
								        inputType:'password',
								        fieldLabel: '密码（默认不修改）'
								    } 
								    ,
								    {
								        xtype: 'textfield',
								        name: 'id_number',
								        value: storeform.get("id_number"),
								        fieldLabel: '省份证号'
								    }
								    ,
								    {
								        xtype: 'textfield',
								        name: 'numbers',
								        value: storeform.get("numbers"),
								        fieldLabel: '工号'
								    }
								    ,
								    {
								        xtype: 'textfield',
								        name: 'leader',
								        value: storeform.get("leader"),
								        fieldLabel: '领导'
								    }
								    ,
								    {
								        xtype: 'textfield',
								        name: ' contact',
								        value: storeform.get("contact"),
								        fieldLabel: '联系方式'
								    }
								    ,
								    
								    {
								        xtype: 'filefield',
								        name: 'authentication',
								        fieldLabel: '省份验证码',
								        buttonText: '选择验证码文件'
								    }
								    ,{// 
					        			xtype: 'fieldcontainer',
							           fieldLabel:'使用情况',
							           defaultType: 'checkboxfield',
											items: [
							            		    	{
							                    boxLabel  : '停用',
							                    name      : 'status',
							                    inputValue: '0'
													
	               									 }
											]
							        
											}
								    
								    ],
								
								    buttons: [{
								        text: '修改',
								        handler: function() {
								            // The getForm() method returns the Ext.form.Basic instance:
								            var form = this.up('form').getForm();
								            if (form.isValid()) {
								            
								                // Submit the Ajax request and handle the response
								                form.submit({
								                    success: function() {
								                    									
								                       //Ext.Msg.alert('Success');
								                       //messageGridStore.load();
						                      												// 
								                      								   },
								                    failure: function(form, action) {
								                      //  Ext.Msg.alert('Failed');
								                       								 }
								                    
								             							   });
								                
								                w.hide();
								                	setTimeout(function(){messageGridStore.load();},1000);
								            }
								        }
								    }]
								})],
						bbar: new Ext.Panel({
											//html: bbarHtml,
								border: false,
							bodyStyle: 'background-color:transparent;padding:3px 10px;'
						})}).show();
						}
					},
					{text:'添加',
						iconCls:'add',
						handler:function(){
						
		    			var w=Ext.create('Ext.window.Window',{title: '添加用户',
						 width: 400,
						minWidth: 200,
						layout: 'anchor',
						closable: true,
						//resizable:false,
						plain: true,
						items: [			        
						        Ext.create('Ext.form.Panel', {
								   // title: '添加用户', 
								    bodyPadding: 5,
								    width: 350,
								    border: false,
								    url: '../servlet/user.add',
								    items: [
									{
									    xtype: 'hiddenfield',
									    name: 'group_id',
									    value: ids
									   
									}
									,
								            
								    {
								        xtype: 'textfield',
								        name: 'name',
								        fieldLabel: '姓名',
								        allowBlank: false  // requires a non-empty value
								    },
								    {
								        xtype: 'textfield',
								        name: 'account',
								        fieldLabel: '账号'
								    }
								    ,
								    {
								        xtype: 'textfield',
								        name: 'password',
								        inputType:'password',
								        fieldLabel: '密码'
								    } 
								    ,
								    {
								        xtype: 'textfield',
								        name: 'id_number',
								        fieldLabel: '省份证号'
								    }
								    ,
								    {
								        xtype: 'textfield',
								        name: 'numbers',
								        fieldLabel: '工号'
								    }
								    ,
								    {
								        xtype: 'textfield',
								        name: 'leader',
								        fieldLabel: '领导'
								    }
								    ,
								    {
								        xtype: 'textfield',
								        name: ' contact',
								        fieldLabel: '联系方式'
								    }
								    ,
								   
								    
								    {
								        xtype: 'filefield',
								        name: 'authentication',
								        fieldLabel: '省份验证码',
								        buttonText: '选择验证码文件'
								    }
								    
								    ],
								
								    buttons: [{
								        text: '提交',
								        handler: function() {
								            // The getForm() method returns the Ext.form.Basic instance:
								            var form = this.up('form').getForm();
								            if (form.isValid()) {
								                // Submit the Ajax request and handle the response
								            	
								                form.submit({
								                    success: function(form, action) {
								                      // Ext.Msg.alert('Success');
								                       //messageGridStore.load();
						                      			 //w.hide();
								                    },
								                    failure: function(form, action) {
								                       // Ext.Msg.alert('Failed');
								                    }
								                });
								                w.hide();
								                	setTimeout(function(){messageGridStore.load();},1000);
								            }
								        }
								    }]
								})],
					bbar: new Ext.Panel({
										//html: bbarHtml,
							border: false,
						bodyStyle: 'background-color:transparent;padding:3px 10px;'
					})}).show();
		        		}
		        	}
			],
			columns:[
				{header:'Id',dataIndex:'___key_id',hidden:true},
				{header:'姓名',dataIndex:'name'},
				{header:'帐号',dataIndex:'account'},
				{header:'省份证号',dataIndex:'id_number'}	,
				{header:'领导',dataIndex:'leader'},
				{header:'工号',dataIndex:'numbers'},
				{header:'联系方式',dataIndex:'contact'},
				{header:'状态',dataIndex:'status',
					renderer: function(value,meta){
			        if (value == 1) {
			        	meta.style='color:green';
			            return '可用';
			        			}
			        meta.style='color:red';
			        return  '停用';
			        
			    }},
				{header:'创建时间',dataIndex:'createtime',flex:1,xtype: 'datecolumn',   format:'Y-m-d'}
			],
			bbar: Ext.create('Ext.PagingToolbar', {
				id:'govInfoGridPagingToolbar_'+this.moduleId,
	            store: messageGridStore,
	            displayInfo: true,
	            displayMsg: '当前 {0} - {1} / {2}',
	            emptyMsg: "没有数据"
	        })
		});
		this.callParent(arguments);
		
		
		//创建登录的panel

	}
	

});